package com.fangshuoit.validator;

import com.fangshuoit.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Created by Fangshuo_zhou on 2018/1/28.
 */
public class MyConstraintValidator implements ConstraintValidator<MyConstraint, Object> {

    //Spring看到MyConstraintValidator实现了ConstraintValidator会自动将其注册为一个Bean;

    @Autowired
    private HelloService helloService;

    @Override
    public void initialize(MyConstraint constraintAnnotation) {
        System.out.println("my validator init");
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        helloService.greeting("tom ");
        System.out.println(value);
        return false;
    }
}
